package foo.bar.blog.core.services;

import org.springframework.orm.jpa.JpaTemplate;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

/**
 * @author tmjee
 * @version $Date$ $Id$
 */
public class AbstractFeedsService extends AbstractJpaAwareService {

    AbstractFeedsService() {}

    public AbstractFeedsService(JpaTemplate template) {
        super(template);
    }


    protected String buildUrlPrefix() {
            ServletRequestAttributes reqAtt = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
            String scheme = reqAtt.getRequest().getScheme();
            String host = reqAtt.getRequest().getLocalAddr();
            int port = reqAtt.getRequest().getLocalPort();
            boolean addPort = (port != 80 && port != 443);
            String contextPath = reqAtt.getRequest().getContextPath();
            return (scheme+"://"+host+(addPort ? ":"+port : "")+contextPath);
    }
}
